package huoye.shops.huoye.operation.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.codeideology.android.widget.recycler.RecyclerViewAdapter;

import java.math.BigDecimal;

import butterknife.BindView;
import huoye.shops.R;
import huoye.shops.base.APIUrls;
import huoye.shops.huoye.operation.model.SellOrder;
import huoye.shops.utils.StockUtils;
import huoye.shops.widget.RoundImageView;


/**
 * Created by uesr on 2018/8/10.
 */

public class SellOrderAdapter extends RecyclerViewAdapter<SellOrderAdapter .ViewHolder,SellOrder> {



    public SellOrderAdapter(Context context) {
        super(context, R.layout.item_sell_order);
    }

    @Override
    protected ViewHolder initViewHolder(View view, int i) {

        return new ViewHolder(view);
    }

    private SellOrder mSellOrder;
    @Override
    protected void bindView(ViewHolder holder, final SellOrder sellOrder, int i) {

        if(getContext() != null){
            Glide.with(getContext())
                    .load(sellOrder.getBuyUserImg())
                    .dontAnimate()
                    .placeholder(R.mipmap.ic_wait_logo)
                    .error(R.mipmap.ic_error)
                    .into(holder.rvHead);
        }

        holder.tvName.setText(sellOrder.getBuyUserName());

        if(getContext() != null){
            Glide.with(getContext())
                    .load(APIUrls.COMMON_CONFIG.TYPE_COMMON_ALIYUN+sellOrder.getOrderImg())
                    .dontAnimate()
                    .placeholder(R.mipmap.ic_wait_logo)
                    .error(R.mipmap.ic_error)
                    .into(holder.rvShop);
        }

        holder.tvShop.setText(sellOrder.getOrderTitle());
        String moenyStyle = StockUtils.moenyStyle(sellOrder.getPayAccount());
        holder.tvMoney.setText("合计："+ moenyStyle+"");
        holder.tvTime.setText(sellOrder.getAddTime());

        switch (sellOrder.getiState()){
            case 1:
                holder.tvStare.setText("待付款");
                holder.tvStare.setTextColor(Color.parseColor("#F5A623"));
                holder.btnDelete.setVisibility(View.VISIBLE);
                break;
            case 2:
                holder.tvStare.setText("待发货");
                holder.tvStare.setTextColor(Color.parseColor("#F5A623"));
                holder.btnSend.setVisibility(View.VISIBLE);
                break;
            case 3:
                holder.tvStare.setText("已发货");
                holder.tvStare.setTextColor(Color.parseColor("#7ED321"));
                holder.btnSend.setVisibility(View.GONE);
                break;
            case 4:
                holder.tvStare.setText("已送达");
                holder.tvStare.setTextColor(Color.parseColor("#9B9B9B"));
                holder.btnSend.setVisibility(View.GONE);
                break;
            case 5:
                holder.tvStare.setText("已完成");
                holder.tvStare.setTextColor(Color.parseColor("#9B9B9B"));
                holder.btnSend.setVisibility(View.GONE);

                break;
            case 6: //退货中
                holder.tvStare.setText("处理中");
                holder.tvStare.setTextColor(Color.parseColor("#7ED321"));
                holder.btnSend.setVisibility(View.GONE);
                break;
            case 7:
                holder.tvStare.setText("已取消");
                holder.tvStare.setTextColor(Color.parseColor("#9B9B9B"));
                holder.btnSend.setVisibility(View.GONE);
                break;


        }


        holder.btnDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onDeleteClick(sellOrder);
            }
        });
        holder.btnSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onSendClick(sellOrder);
            }
        });
    }


    public class ViewHolder extends RecyclerViewAdapter.ViewHolder {

        @BindView(R.id.item_sell_order_tv_name)
        TextView tvName;
        @BindView(R.id.item_sell_order_tv_state)
        TextView tvStare;
        @BindView(R.id.item_sell_order_tv_shop)
        TextView tvShop;
        @BindView(R.id.item_sell_order_tv_money)
        TextView tvMoney;
        @BindView(R.id.item_sell_order_tv_time)
        TextView tvTime;


        @BindView(R.id.item_sell_order_rv_head)
        RoundImageView rvHead ;
        @BindView(R.id.item_sell_order_rv_shop)
        RoundImageView rvShop ;

        @BindView(R.id.item_sell_order_btn_delete)
        Button btnDelete ;
        @BindView(R.id.item_sell_order_btn_send)
        Button btnSend ;


        public ViewHolder(View itemView) {
            super(itemView);
        }
    }



    public void setOnSellOrderListener(OnSellOrderListener onSellOrderListener) {
        this.listener = onSellOrderListener;
    }

    private OnSellOrderListener listener;

    public interface OnSellOrderListener {

        void onDetailsClick(SellOrder sellOrder);
        void onDeleteClick(SellOrder sellOrder);
        void onSendClick(SellOrder sellOrder);

    }

}
